package com.zht.demo;

//import cn.ucox.web.framework.security.MD5Util;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections4.CollectionUtils;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.text.SimpleDateFormat;
import java.util.*;

public class Demo {

    private static String ENCODE_FACTOR = "KOKLGLC8712A4365";
    private static String KEY_ALGORITHM = "AES";

    public static void main(String[] args) {
//        long time = System.currentTimeMillis();
////        String oauth = (int)(Math.random() * 10) + UUID.randomUUID().toString().replace("-", "") + MD5Util.md5Str("vuex/store"+time) + (int)(Math.random() * 10);
////        System.out.println(oauth);
//        System.out.println(time);
//
//        // 2023-07-28
//        String gxsj = "1690525568000";
//        // 1999-03-24
//        String scrq = "922204800000";
//        // 2019-08-14
//        String cyjmsfzqk = "1565712000000";
//        Date date1 = new Date(Long.valueOf(scrq));
//        Date date2 = new Date(Long.valueOf(cyjmsfzqk));
//
//
//        String format = new SimpleDateFormat("yyyy-MM-dd").format(date1);
//        String format2 = new SimpleDateFormat("yyyy-MM-dd").format(date2);
//        System.out.println(format);
//        System.out.println(format2);
//
//        String rq = "2019-08-14";
//        String substring = rq.substring(0, 4);
//        String substring1 = rq.substring(5, 7);
//        String substring2 = rq.substring(8, 10);
//        System.out.println(substring);

//        String s = "KOKLGLC8712A4365";
//        String encode = encode("Tms0304!", ENCODE_FACTOR);
//        System.out.println(encode);

//        List<Long> selectList = new ArrayList();
//        List<Long> vueList = new ArrayList();
//        selectList.add(1L);
//        selectList.add(2L);
//        selectList.add(3L);
//        selectList.add(4L);
//        vueList.add(1L);
//        vueList.add(4L);
//        // 获取差集 [1,2]
//        List<Long> difference = (List<Long>) CollectionUtils.subtract(selectList, vueList);
//
//        Long[] longs = new Long[difference.size()];
//        if (longs!= null && longs.length>0){
//            Long[] longs1 = difference.toArray(longs);
//            for (int i = 0; i < longs1.length; i++) {
//                System.out.println(longs1[i]);
//            }
//        }
//        System.out.println(longs);

//        String s = "134;789";
//        String[] split = s.split(";");
//        for (int i = 0; i < split.length; i++) {
//            System.out.println(split[i]);
//        }

//        StringBuilder str = new StringBuilder();
//        str.append("数据一").append("数据二");
//        str.append("数据三");
//        str.append("数据四").append(1);
//        System.out.println(str);
//
//        String appId = "cu-wisdomlaw";
//        String app_secret = "CU#3sMYv8DN#sa";
//

        //获取程序目录
        String property = System.getProperty("user.dir");
        System.out.println(property);

        // 添加6位随机数
        Random random = new Random();
        String randomNumber = String.format("%06d", random.nextInt(1_000_000));
//        Date date = new Date();
//
//        String timestamp = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss SSS");
//
//        String transId = DateUtil.format(date, DatePattern.PURE_DATETIME_MS_FORMAT);
//
//        System.out.println("randomNumber:>>" + randomNumber);
//        System.out.println("transId:>>" + transId);
//
//        System.out.println("时间:>>" + timestamp);
//        String str = transId+randomNumber;
//        System.out.println("最终结果:>>" + str);
//
//        System.out.println("------------------------------------------------");
//        // 计算token
//        String s = "appId" + appId + "timestamp" + timestamp + "transId" + str + app_secret;
//        System.out.println("s:>" + s);
//        String token = MD5.create().digestHex(s);
//        System.out.println("token:>" + token);



    }


    /**
     * 加密
     *
     * @param txt    需要加密的字符串
     * @param factor 加密秘钥
     */
    public static String encode(String txt, String factor) {
        if (StrUtil.isBlank(txt)) {
            return txt;
        }

        try {
            // "算法/模式/补码方式"
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            SecretKey key = new SecretKeySpec(factor.getBytes("utf-8"), KEY_ALGORITHM);

            // 初始化密码器，第一个参数为加密(Encrypt_mode)或者解密解密(Decrypt_mode)操作，第二个参数为使用的KEY
            cipher.init(Cipher.ENCRYPT_MODE, key);

            byte[] encrypted = cipher.doFinal(txt.getBytes("utf-8"));

            // 将字符串返回
            return Base64.encodeBase64String(encrypted);
        } catch (Exception e) {
            throw new RuntimeException("加密失败", e);
        }
    }
}
